import*as e from"../helpers/helpers.js";import*as t from"../icon_button/icon_button.js";import*as o from"../../lit-html/lit-html.js";import"../../legacy/legacy.js";const s=new CSSStyleSheet;s.replaceSync(".markdown-image{display:block}\n/*# sourceURL=markdownImage.css */\n");const r=new Map([]),n=e=>{const t=r.get(e);if(!t)throw new Error(`Markdown image with key '${e}' is not available, please check MarkdownImagesMap.ts`);return t};var a=Object.freeze({__proto__:null,markdownImages:r,getMarkdownImage:n});class i extends HTMLElement{static litTagName=o.literal`devtools-markdown-image`;#e=this.attachShadow({mode:"open"});#t;#o;connectedCallback(){this.#e.adoptedStyleSheets=[s]}set data(e){const{key:t,title:o}=e,s=n(t);this.#t=s,this.#o=o,this.#s()}#r(){if(!this.#t)return o.html``;const{src:e,color:s,width:r="100%",height:n="100%"}=this.#t;return o.html` <${t.Icon.Icon.litTagName} .data="${{iconPath:e,color:s,width:r,height:n}}"></${t.Icon.Icon.litTagName}> `}#n(){if(!this.#t)return o.html``;const{src:e,width:t="100%",height:s="100%"}=this.#t;return o.html` <img class="markdown-image" src="${e}" alt="${this.#o}" width="${t}" height="${s}/"> `}#s(){if(!this.#t)return;const{isIcon:e}=this.#t,t=e?this.#r():this.#n();o.render(t,this.#e,{host:this})}}e.CustomElements.defineComponent("devtools-markdown-image",i);var l=Object.freeze({__proto__:null,MarkdownImage:i});const c=new CSSStyleSheet;c.replaceSync(".devtools-link{color:var(--color-link);outline-offset:2px;text-decoration:none}.devtools-link:hover{text-decoration:underline}\n/*# sourceURL=markdownLink.css */\n");const h=new Map([["issuesContrastWCAG21AA","https://www.w3.org/TR/WCAG21/#contrast-minimum"],["issuesContrastWCAG21AAA","https://www.w3.org/TR/WCAG21/#contrast-enhanced"],["issuesContrastSuggestColor","https://developers.google.com/web/updates/2020/08/devtools#accessible-color"],["issuesCSPSetStrict","https://web.dev/strict-csp"],["issuesCSPWhyStrictOverAllowlist","https://web.dev/strict-csp/#why-a-strict-csp-is-recommended-over-allowlist-csps"],["issueCorsPreflightRequest","https://web.dev/cross-origin-resource-sharing/#preflight-requests-for-complex-http-calls"],["issueQuirksModeDoctype","https://web.dev/doctype/"],["sameSiteAndSameOrigin","https://web.dev/same-site-same-origin/"],["punycodeReference","https://wikipedia.org/wiki/Punycode"],["https://xhr.spec.whatwg.org/","https://xhr.spec.whatwg.org/"],["https://goo.gle/chrome-insecure-origins","https://goo.gle/chrome-insecure-origins"],["https://webrtc.org/web-apis/chrome/unified-plan/","https://webrtc.org/web-apis/chrome/unified-plan/"],["https://developer.chrome.com/blog/enabling-shared-array-buffer/","https://developer.chrome.com/blog/enabling-shared-array-buffer/"],["https://developer.chrome.com/docs/extensions/mv3/","https://developer.chrome.com/docs/extensions/mv3/"],["https://developer.chrome.com/blog/immutable-document-domain/","https://developer.chrome.com/blog/immutable-document-domain/"],["https://github.com/WICG/shared-element-transitions/blob/main/debugging_overflow_on_images.md","https://github.com/WICG/shared-element-transitions/blob/main/debugging_overflow_on_images.md"],["https://developer.chrome.com/docs/extensions/reference/privacy/#property-websites-privacySandboxEnabled","https://developer.chrome.com/docs/extensions/reference/privacy/#property-websites-privacySandboxEnabled"]]),m=e=>{if(/^https:\/\/www.chromestatus.com\/feature\/\d+$/.test(e))return e;const t=h.get(e);if(!t)throw new Error(`Markdown link with key '${e}' is not available, please check MarkdownLinksMap.ts`);return t};var d=Object.freeze({__proto__:null,markdownLinks:h,getMarkdownLink:m});class p extends HTMLElement{static litTagName=o.literal`devtools-markdown-link`;#e=this.attachShadow({mode:"open"});#a="";#i="";connectedCallback(){this.#e.adoptedStyleSheets=[c]}set data(e){const{key:t,title:o}=e,s=m(t);this.#a=o,this.#i=s,this.#s()}#s(){const e=o.html` <x-link class="devtools-link" href="${this.#i}">${this.#a}</x-link> `;o.render(e,this.#e,{host:this})}}e.CustomElements.defineComponent("devtools-markdown-link",p);var g=Object.freeze({__proto__:null,MarkdownLink:p});const w=new CSSStyleSheet;w.replaceSync('.message{line-height:20px;font-size:14px;color:var(--color-text-secondary);margin-bottom:4px;user-select:text}.message p{margin-bottom:16px;margin-block-start:2px}.message ul{list-style-type:none;list-style-position:inside;padding-inline-start:0}.message li{margin-top:8px;display:list-item}.message li::before{content:"→";-webkit-mask-image:none;padding-right:5px;position:relative;top:-1px}.message code{color:var(--color-text-primary);font-size:12px;user-select:text;cursor:text;background:var(--color-background-elevation-1)}\n/*# sourceURL=markdownView.css */\n');const u=o.html,k=o.render;class b extends HTMLElement{static litTagName=o.literal`devtools-markdown-view`;#e=this.attachShadow({mode:"open"});#l=[];connectedCallback(){this.#e.adoptedStyleSheets=[w]}set data(e){this.#l=e.tokens,this.#c()}#c(){this.#s()}#s(){k(u` <div class="message"> ${this.#l.map(S)} </div> `,this.#e,{host:this})}}e.CustomElements.defineComponent("devtools-markdown-view",b);const v=e=>{if("tokens"in e&&e.tokens)return e.tokens.map(S);throw new Error("Tokens not found")},f=e=>{const t=new Map([["&amp;","&"],["&lt;","<"],["&gt;",">"],["&quot;",'"'],["&#39;","'"]]);return e.replace(/&(amp|lt|gt|quot|#39);/g,(e=>{const o=t.get(e);return o||e}))},x=e=>"tokens"in e&&e.tokens?u`${v(e)}`:u`${f("text"in e?e.text:"")}`;function y(e){switch(e.type){case"paragraph":return u`<p>${v(e)}`;case"list":return u`<ul>${e.items.map(S)}</ul>`;case"list_item":return u`<li>${v(e)}`;case"text":return x(e);case"codespan":return u`<code>${f(e.text)}</code>`;case"space":return u``;case"link":return u`<${p.litTagName} .data="${{key:e.href,title:e.text}}"></${p.litTagName}>`;case"image":return u`<${i.litTagName} .data="${{key:e.href,title:e.text}}"></${i.litTagName}>`;case"heading":return(e=>{switch(e.depth){case 1:return u`<h1>${x(e)}</h1>`;case 2:return u`<h2>${x(e)}</h2>`;case 3:return u`<h3>${x(e)}</h3>`;case 4:return u`<h4>${x(e)}</h4>`;case 5:return u`<h5>${x(e)}</h5>`;default:return u`<h6>${x(e)}</h6>`}})(e);case"strong":return u`<strong>${x(e)}</strong>`;case"em":return u`<em>${x(e)}</em>`;default:return null}}const S=e=>{const t=y(e);if(null===t)throw new Error(`Markdown token type '${e.type}' not supported.`);return t};var $=Object.freeze({__proto__:null,MarkdownView:b,renderToken:S});export{l as MarkdownImage,a as MarkdownImagesMap,g as MarkdownLink,d as MarkdownLinksMap,$ as MarkdownView};
